|
|
|
|
|
|
|
(ByVal lpString As Long) As Long
Declare Function lstrcpyfromptr Lib "kernel32" Alias "lstrcpyA" _
(ByVal lpString1 As String, ByVal lpString2 As Long) As Long |
|
|
|
|
|
|
|
|
The lstrlenptr function uses the lstrlen API function to obtain the length of a string. Note, however, that we've declared the function to use a Long variable. This is because we are going to pass it a pointer value rather than a string. The same technique is used in the lstrcpyfromptr function, which copies a string from a location in memory to a Visual Basic string. To make things easier, you can use the following VB function, which takes a memory address, obtains the length of the string, allocates a Visual Basic string, and loads it from the memory address: |
|
|
|
|
|
|
|
|
Private Function LoadStringFromPtr(ByVal ptrval&) As String
Dim slen&
Dim resstring$
If ptrval = 0 Then Exit Function
slen = lstrlenptr(ptrval)
resstring = String$(slen + 1, 0)
Call lstrcpyfromptr(resstring, ptrval)
LoadStringFromPtr = Left$(resstring, slen)
End Function |
|
|
|
|
|
|
|
|
The resstring variable is initially defined with one extra byte. This is because the lstrcpyfromptr function will copy a terminating NULL character along with the string data. The final step is to use the Left$ function to strip off the NULL character, which is not needed in a Visual Basic string. |
|
|
|
|
|
|
|
|
Going back to the event log, the first string to appear after the EVENTLOGRECORD structure in the buffer is a string describing the source of the event. The location of this string will be at pevlr + Len(ev). This is the final piece of the Visual Basic routine for reading events. The routine corresponds closely to the C example shown earlier: |
|
|
|
|
|
|
|
|
Private Sub Command1_Click()
Dim h As Long
Dim ev As EVENTLOGRECORD
Dim pevlr As Long
h = OpenEventLog(vbNullString, "Application")
List1.Clear
If h <> 0 Then |
|
|
|
|
|